// Decompiled by Jad v1.5.7f. Copyright 2000 Pavel Kouznetsov.
// Jad home page: http://www.geocities.com/SiliconValley/Bridge/8617/jad.html
// Decompiler options: packimports(3) 
// Source File Name:   NoteServiceImp.java

package com.iphaeton.lms.business.note;

import com.iphaeton.common.helper.Pagination;
import com.iphaeton.exception.BusinessException;
import com.iphaeton.exception.PersistenceException;
import com.iphaeton.lms.business.PersistentServiceSupport;
import com.iphaeton.lms.pojo.note.Note;
import com.iphaeton.persistence.IPersistenceService;
import java.util.List;
import org.apache.log4j.Logger;

// Referenced classes of package com.iphaeton.lms.business.note:
//            INoteService

public class NoteServiceImp extends PersistentServiceSupport
    implements INoteService
{

    public NoteServiceImp()
    {
    }

    public void store(Note n)
        throws BusinessException
    {
        try
        {
            hbpservice.store(n);
        }
        catch(PersistenceException e)
        {
            e.printStackTrace();
            throw new BusinessException("\u6301\u4E45\u5316\u7B14\u8BB0\u5BF9\u8C61\u5931\u8D25!");
        }
    }

    public void remove(String id)
        throws BusinessException
    {
        try
        {
            hbpservice.remove(id, com.iphaeton.lms.pojo.note.Note.class);
        }
        catch(PersistenceException e)
        {
            e.printStackTrace();
            throw new BusinessException("\u5220\u9664\u7B14\u8BB0\u65F6\u51FA\u9519!");
        }
    }

    public Note findNoteById(String id)
        throws BusinessException
    {
        Note note = null;
        try
        {
            note = (Note)hbpservice.get(id, com.iphaeton.lms.pojo.note.Note.class);
        }
        catch(PersistenceException e)
        {
            e.printStackTrace();
            throw new BusinessException("\u6839\u636EID\u67E5\u627E\u7B14\u8BB0\u5931\u8D25!");
        }
        return note;
    }

    public List findMyCourse(String id)
        throws BusinessException
    {
        String hql = "select distinct(uc.course) from UserCourse uc where uc.userId='" + id + "'";
        List list;
        try
        {
            list = hbpservice.query(hql);
        }
        catch(PersistenceException e)
        {
            e.printStackTrace();
            throw new BusinessException("\u67E5\u8BE2\u7528\u6237\u8BFE\u7A0B\u51FA\u9519!");
        }
        return list;
    }

    public Pagination getNoteList(String organize_url, String course_id, String row, int state, int pageSize)
        throws BusinessException
    {
        String selectHql = "select count(id) as count from Note n where n.self=1 and n.user.organize.url like '" + organize_url + "%'";
        String queryHql = "from Note n where n.self=1 and n.user.organize.url like '" + organize_url + "%' ";
        if(state == 1)
        {
            selectHql = selectHql + " and n.state=1";
            queryHql = queryHql + " and n.state=1";
        } else
        {
            selectHql = selectHql + " and n.state in (1,2) ";
            queryHql = queryHql + " and n.state in (1,2)  ";
        }
        if(course_id != null && !"".equals(course_id))
        {
            selectHql = selectHql + " and n.course_id='" + course_id + "'";
            queryHql = queryHql + " and n.course_id='" + course_id + "'";
        }
        if(row != null && !"".equals(row))
            queryHql = queryHql + " order by n." + row;
        else
            queryHql = queryHql + " order by n.create_time desc ";
        List list = null;
        try
        {
            list = hbpservice.query(selectHql);
        }
        catch(PersistenceException e)
        {
            e.printStackTrace();
            throw new BusinessException("\u67E5\u8BE2\u7528\u6237\u7B14\u8BB0\u5217\u8868\u5931\u8D25!");
        }
        int itemCount = list.size() <= 0 ? 0 : ((Integer)list.get(0)).intValue();
        int totalPage = ((itemCount + pageSize) - 1) / pageSize;
        if(totalPage < 1)
            totalPage = 1;
        Pagination pageInfo = new Pagination(totalPage, itemCount, pageSize);
        pageInfo.setHqlQueryString(queryHql);
        return pageInfo;
    }

    public Pagination selectNote(String user_id, String course_id, String row, int state, int pageSize)
        throws BusinessException
    {
        if(row == null || "".equals(row))
            row = "create_time";
        String selectHql = "select count(id) as count from Note n ";
        String queryHql = "from Note n ";
        if(state == 1)
        {
            selectHql = selectHql + " where n.state=1";
            queryHql = queryHql + " where n.state=1";
        } else
        {
            selectHql = selectHql + " where n.state in (1,2) ";
            queryHql = queryHql + " where n.state in (1,2) ";
        }
        if(user_id != null && !"".equals(user_id))
        {
            selectHql = selectHql + " and n.create_id='" + user_id + "'";
            queryHql = queryHql + " and n.create_id='" + user_id + "'";
        }
        if(course_id != null && !"".equals(course_id))
        {
            selectHql = selectHql + " and n.course_id='" + course_id + "'";
            queryHql = queryHql + " and n.course_id='" + course_id + "'";
        }
        if(row != null && !"".equals(row))
            queryHql = queryHql + " order by n." + row;
        else
            queryHql = queryHql + " order by n.create_time desc";
        List list = null;
        try
        {
            list = hbpservice.query(selectHql);
        }
        catch(PersistenceException e)
        {
            e.printStackTrace();
            throw new BusinessException("\u67E5\u8BE2\u7528\u6237\u7B14\u8BB0\u5217\u8868\u5931\u8D25!");
        }
        int itemCount = list.size() <= 0 ? 0 : ((Integer)list.get(0)).intValue();
        int totalPage = ((itemCount + pageSize) - 1) / pageSize;
        if(totalPage < 1)
            totalPage = 1;
        Pagination pageInfo = new Pagination(totalPage, itemCount, pageSize);
        pageInfo.setHqlQueryString(queryHql);
        return pageInfo;
    }

    public Pagination findCourseNote(String sortId, String courseId, String row, int state, int pageSize)
        throws BusinessException
    {
        String selectHql = "select count(id) as count from Note n where n.self=1 ";
        String queryHql = "from Note n where n.self=1 ";
        if(sortId != null && !"".equals(sortId))
        {
            selectHql = selectHql + " and n.course.sortId='" + sortId + "'";
            queryHql = queryHql + " and n.course.sortId='" + sortId + "'";
        } else
        if(courseId != null && !"".equals(courseId))
        {
            selectHql = selectHql + " and n.course_id='" + courseId + "'";
            queryHql = queryHql + " and n.course_id='" + courseId + "'";
        }
        if(state == 1)
        {
            selectHql = selectHql + " and n.state=1";
            queryHql = queryHql + " and n.state=1";
        } else
        {
            selectHql = selectHql + " and n.state in (1,2)";
            queryHql = queryHql + " and n.state in (1,2)";
        }
        if(row != null && !"".equals(row))
            queryHql = queryHql + " order by n." + row;
        else
            queryHql = queryHql + " order by n.create_time desc";
        List list = null;
        try
        {
            list = hbpservice.query(selectHql);
        }
        catch(PersistenceException e)
        {
            e.printStackTrace();
            throw new BusinessException("\u67E5\u8BE2\u8BFE\u7A0B\u7B14\u8BB0\u5217\u8868\u5931\u8D25!");
        }
        int itemCount = list.size() <= 0 ? 0 : ((Integer)list.get(0)).intValue();
        int totalPage = ((itemCount + pageSize) - 1) / pageSize;
        if(totalPage < 1)
            totalPage = 1;
        Pagination pageInfo = new Pagination(totalPage, itemCount, pageSize);
        pageInfo.setHqlQueryString(queryHql);
        return pageInfo;
    }

    public List getSpecifiedNote(Pagination pageInfo)
        throws BusinessException
    {
        return getSpecifiedItems(pageInfo);
    }

    private static Logger logger;
    static Class class$0; /* synthetic field */
    static Class class$1; /* synthetic field */

    static 
    {
        logger = Logger.getLogger(com.iphaeton.lms.business.note.NoteServiceImp.class.getName());
    }
}
